package cl.ccs.migracionbcmc.util;


import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;


public class StringUtil {

    public final static String EMPTY = "";
    public final static String NEWLINE = "\r\n";

    private StringUtil() {
        super();
    }

    /**
     *
     * @param str
     * @return
     */
    public static String defaultString(String str) {
        if (null == str) {
            return EMPTY;
        } else {
            return str;
        }
    }

    /**
     *
     * @param str
     * @param trim
     * @return
     */
    public static String defaultString(String str, boolean trim) {
        str = defaultString(str);
        str = str.trim();
        return str;
    }

    /**
     *
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        boolean empty = (null == str) || (str.trim().isEmpty());
        return empty;
    }

    /**
     *
     * @param str
     * @return
     */
    public static boolean isNotEmpty(String str) {
        boolean not_empty = (null != str) && !(str.trim().isEmpty());
        return not_empty;
    }

    public static String dateToString(Date date, String format) {
        DateFormat dateFormat = new SimpleDateFormat(format);
        String strDate = dateFormat.format(date);
        return strDate;
    }

}
